package com.gzf.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gzf.dto.Animal;
import com.gzf.feign.AnimalFeignClient;
import com.gzf.mapper.UserMapper;
import com.gzf.pojo.User;
import com.gzf.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author gzf
 * @since 2019-07-26
 */
@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private AnimalFeignClient animalFeignClient;

    @Override
    @GlobalTransactional
    public boolean save(User entity) {
        Integer insert = userMapper.save(entity);
        if (insert > 0) {
            Animal animal = new Animal();
            animal.setId(entity.getId());
            animal.setName("cdlw");
            Boolean flag = animalFeignClient.insert(animal);
            if (!flag) {
                throw new NullPointerException("hehe");
            }
        }
        return true;
    }
}
